package cn.edu.neusoft.service.car;

import cn.edu.neusoft.config.OauthConfigUtil;
import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
import com.dahuatech.icc.oauth.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CarPeccancyHandler {
    @Autowired
    private OauthConfigUtil oauthConfigUtil;
    public CarPeccancyResponse getCarPeccancyInfoByTime(CarPeccancyRequest carPeccancyRequest) {
        OauthConfigUserPwdInfo config = oauthConfigUtil.getOauthConfig();
        CarPeccancyResponse response=null;

        try {
            log.info("CarPeccancyHandler,getCarPeccancyInfoByTime,request:{}", JSONUtil.toJsonStr(carPeccancyRequest));
            response = HttpUtils.executeJson("/evo-apigw/evo-car/1.0.0/carPeccancy/getPeccancys",carPeccancyRequest,null, Method.POST , config, CarPeccancyResponse.class);

        } catch (ClientException e) {
            log.error(e.getErrMsg(), e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(!response.getCode().equals("1000")) {
            log.info("获取违章信息失败:{}.{}",response.getDesc(),response.getCode());
        }
        return response;
    }
}